package main;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.Scanner;

import nmf.CenterNearTheAverageNMFTool;
import nmf.FeatureSparsenessNMFTool;
import nmf.NMFTool;
import nmf.OriginalDataNMFTool;
import nmf.SimpleFeatureSelectionNMFTool;
import nmf.SimpleNMFTool;
import nmf.TitleFeatureNMFTool;

public class ComprehensiveNMFTest {
   
   public static ArrayList<Integer> innerDim = new ArrayList<Integer>();
   public static int trainingSetSize = -1;
   public static char comparisonType;
   public static ArrayList<String> fileNames = new ArrayList<String>();
   public static ArrayList<NMFTool> nmfTools = new ArrayList<NMFTool>();
   
   public static void main(final String args[]) throws FileNotFoundException {
      //System.setIn(new FileInputStream("C://Users//Garrett//workspace//nmf-text-mining-480-2//nmf-text-mining-480//runConfigs//SimpleInitializationTest2Documents"));
      //System.setIn(new FileInputStream("C://Users//Garrett//workspace//nmf-text-mining-480-2//nmf-text-mining-480//runConfigs//SparsenessDimensionTest2Documents"));
      //System.setIn(new FileInputStream("C://Users//Garrett//workspace//nmf-text-mining-480-2//nmf-text-mining-480//runConfigs//SimpleVsSparseFeature4Documents9Known"));
      //System.setIn(new FileInputStream("C://Users//Garrett//workspace//nmf-text-mining-480-2//nmf-text-mining-480//runConfigs//NoFactor5Collections"));
      //System.setIn(new FileInputStream("runConfigs/dataCollector"));
      //System.setIn(new FileInputStream("runConfigs/LargeRun"));
      //System.setIn(new FileInputStream("runConfigs/SimpleHarvester"));
      System.setIn(new FileInputStream("runConfigs/TitleFeature"));
      getUserInput();
      //trainingSetSize = 6;
      //NMFTestProcessFixedR nmfProcess;
      NMFRandomTestProcess nmfProcess;
      //nmfProcess = new NMFTestProcessFixedR(fileNames, nmfTools, innerDim, trainingSetSize);
      nmfProcess = new NMFRandomTestProcess(fileNames, nmfTools, innerDim, trainingSetSize, 25);
      nmfProcess.run();
   }
   
   public static void getUserInput() {
      char resp;
      final Scanner sc = new Scanner(System.in);
      
      System.out.print("Enter in [d]irectory name or [f]ile names manually? ");
      resp = sc.next().toUpperCase().charAt(0);
      
      if (resp == 'D') {
         System.out.print("Enter in directory name: ");
         final File dir = new File(sc.next());
         
         System.out.print("How many files in this directory do you want to use? ");
         int numberOfFiles = sc.nextInt();
         
         if (dir.isDirectory()) {
            for (final String fileName : dir.list()) {
               fileNames.add(dir.getName() + "/" + fileName);
               if (--numberOfFiles == 0) {
                  break;
               }
            }
         }
      }
      else {
         System.out.println("Enter the filename: ");
         fileNames.add(sc.next());
      }
      
      System.out.print("How many documents are known in each file? ");
      trainingSetSize = sc.nextInt();
      
      System.out.print("[I]niitialization comparison, or Inner [d]imension comparison? ");
      comparisonType = sc.next().toUpperCase().charAt(0);
      
      if (comparisonType == 'I') {
         System.out.print("Enter in minimum dimension, maximum dimension, and step size: ");
         final int min = sc.nextInt(), max = sc.nextInt(), step = sc.nextInt();
         for (int i = min; i <= max; i += step) {
            innerDim.add(i);
         }
         
         System.out.println("Enter the numbers associated with the initializations you wish to test: ");
         System.out.println("1. Simple Random Initialization");
         System.out.println("2. Feature Sparseness Initialization");
         System.out.println("3. Weighted Feature Initialization");
         System.out.println("4. Use original data matrix");
         System.out.println("5. Use Center Near the Average");
         System.out.println("6. Title Feature Initialization");
         
         final String nmfChoices = sc.next();
         if (nmfChoices.contains("1")) {
            nmfTools.add(new SimpleNMFTool());
         }
         if (nmfChoices.contains("2")) {
            nmfTools.add(new FeatureSparsenessNMFTool());
         }
         if (nmfChoices.contains("3")) {
            nmfTools.add(new SimpleFeatureSelectionNMFTool());
         }
         if (nmfChoices.contains("4")) {
            nmfTools.add(new OriginalDataNMFTool());
         }
         if (nmfChoices.contains("5")) {
            nmfTools.add(new CenterNearTheAverageNMFTool());
         }
         if(nmfChoices.contains("6")) {
            nmfTools.add(new TitleFeatureNMFTool());
         }
         
      }
      else if (comparisonType == 'D') { 
         
         System.out.print("Enter in minimum dimension, maximum dimension, and step size: ");
         final int min = sc.nextInt(), max = sc.nextInt(), step = sc.nextInt();
         for (int i = min; i <= max; i += step) {
            innerDim.add(i);
         }
         
         System.out.println("Enter the number associated with the initialization you wish to test: ");
         System.out.println("1. Simple Random Initialization");
         System.out.println("2. Feature Sparseness Initialization");
         System.out.println("3. Weighted Feature Initialization");
         System.out.println("4. Use original data matrix");
         System.out.println("5. Use Center Near the Average");
         System.out.println("6. Title Feature Initialization");
         
         final String nmfChoices = sc.next();
         if (nmfChoices.contains("1")) {
            nmfTools.add(new SimpleNMFTool());
         }
         if (nmfChoices.contains("2")) {
            nmfTools.add(new FeatureSparsenessNMFTool());
         }
         if (nmfChoices.contains("3")) {
            nmfTools.add(new SimpleFeatureSelectionNMFTool());
         }
         if (nmfChoices.contains("4")) {
            nmfTools.add(new OriginalDataNMFTool());
         }
         if (nmfChoices.contains("5")) {
            nmfTools.add(new CenterNearTheAverageNMFTool());
         }
         if(nmfChoices.contains("6")) {
            nmfTools.add(new TitleFeatureNMFTool());
         }
         
      }
      System.out.println();
   }
   
}
